package com.hw.saweb.dao;

import com.hw.sacommon.Constant;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @program: sa-token-start
 * @author: hewei
 * @date: 2023-09-05 17:43
 *
 * 模拟权限数据
 * 权限通配符：
 *      *.delete 支持任何的 delete 操作
 *      user.*   支持 user 的任何操作
 **/

@Component
public class UserPermissionDao {

    private static final HashMap<Long, List<String>> USER_ROLE = new HashMap<>();
    private static final HashMap<Long, List<String>> USER_PERMISSION = new HashMap<>();

    @PostConstruct
    private void init() {
        List<String> list = new ArrayList<>();
        list.add("user.add");
        list.add("user.update");
        list.add("user.other");
//        list.add("user.get");
//        list.add("user.delete");
        list.add("*.get");
        list.add("art.*");
        USER_PERMISSION.put(Constant.USER_ID, list);

        List<String> rlist = new ArrayList<>();
        rlist.add("admin");
        rlist.add("root");
        rlist.add("user");
        rlist.add("service");
        rlist.add("session");
        rlist.add("annotation");
        USER_ROLE.put(Constant.USER_ID, rlist);
    }

    public static List<String> getUserPermissions(Long userId){
        return USER_PERMISSION.get(userId);
    }
    public static List<String> getUserRoles(Long userId){
        return USER_ROLE.get(userId);
    }

}
